import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CommissionPolicyApi } from '#/api/spa/commission/policy';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'policyCode',
      label: '策略编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入策略编码',
      },
    },
    {
      fieldName: 'policyName',
      label: '策略名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入策略名称',
      },
    },
    {
      fieldName: 'staffType',
      label: '适用员工类型',
      rules: 'required',
      // component: 'Select',
      // componentProps: {
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择适用员工类型',
      // },
    },
    {
      fieldName: 'commissionType',
      label: '提成类型',
      rules: 'required',
      // component: 'Select',
      // componentProps: {
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择提成类型',
      // },
    },
    {
      fieldName: 'conditionConfig',
      label: '条件配置(JSON，例如：服务类别=按摩, 金额区间=100-500)',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder:
          '请输入条件配置(JSON，例如：服务类别=按摩, 金额区间=100-500)',
      },
    },
    {
      fieldName: 'commissionFormula',
      label: '提成公式(JSON，例如：base_amount * 0.05)',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入提成公式(JSON，例如：base_amount * 0.05)',
      },
    },
    {
      fieldName: 'priority',
      label: '优先级',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入优先级',
      },
    },
    {
      fieldName: 'startTime',
      label: '生效时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'endTime',
      label: '失效时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      // component: 'RadioGroup',
      // componentProps: {
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   buttonStyle: 'solid',
      //   optionType: 'button',
      // },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'policyCode',
      label: '策略编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入策略编码',
      },
    },
    {
      fieldName: 'policyName',
      label: '策略名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入策略名称',
      },
    },
    {
      fieldName: 'staffType',
      label: '适用员工类型',
      // component: 'Select',
      // componentProps: {
      //   allowClear: true,
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择适用员工类型',
      // },
    },
    {
      fieldName: 'commissionType',
      label: '提成类型',
      // component: 'Select',
      // componentProps: {
      //   allowClear: true,
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择提成类型',
      // },
    },
    {
      fieldName: 'conditionConfig',
      label: '条件配置(JSON，例如：服务类别=按摩, 金额区间=100-500)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder:
          '请输入条件配置(JSON，例如：服务类别=按摩, 金额区间=100-500)',
      },
    },
    {
      fieldName: 'commissionFormula',
      label: '提成公式',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入提成公式(JSON，例如：base_amount * 0.05)',
      },
    },
    {
      fieldName: 'priority',
      label: '优先级',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入优先级',
      },
    },
    {
      fieldName: 'startTime',
      label: '生效时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'endTime',
      label: '失效时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<CommissionPolicyApi.CommissionPolicy>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'policyCode',
      title: '策略编码',
      minWidth: 120,
    },
    {
      field: 'policyName',
      title: '策略名称',
      minWidth: 120,
    },
    {
      field: 'staffType',
      title: '适用员工类型',
      minWidth: 120,
    },
    {
      field: 'commissionType',
      title: '提成类型',
      minWidth: 120,
    },
    {
      field: 'conditionConfig',
      title: '条件配置(JSON，例如：服务类别=按摩, 金额区间=100-500)',
      minWidth: 120,
    },
    {
      field: 'commissionFormula',
      title: '提成公式(JSON，例如：base_amount * 0.05)',
      minWidth: 120,
    },
    {
      field: 'priority',
      title: '优先级',
      minWidth: 120,
    },
    {
      field: 'startTime',
      title: '生效时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'endTime',
      title: '失效时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
